package com.server.servlet.product;

import com.bean.Message;
import com.bean.Product;
import com.server.service.ProductService;
import com.server.service.impl.ProductServiceImpl;
import com.server.servlet.Servlet;

public abstract class ProductServletImpl extends Servlet {
	
	private static final String SUCCESS_CODE = "3";
	private static final String FAILED_CODE = "0";
	
	protected ProductService service;
	protected Product requestProduct;
	protected Product resultProduct;
	
	@Override
	public void onCreate() {
		service = new ProductServiceImpl();
	}

	@Override
	public void receiveMessage(Message msg) {
		initData(msg);
		if(isSuccess()) {
			success(msg);
		} else {
			failed(msg);
		}
	}
	
	protected abstract void initData(Message msg);
	
	protected void success(Message msg) {
		msg.setRespCode(SUCCESS_CODE);
		msg.setRespDes("操作成功。");
	}
	
	protected void failed(Message msg) {
		msg.setRespCode(FAILED_CODE);
		msg.setRespDes("操作失败。");
	}
	
	protected abstract boolean isSuccess();
	
}
